﻿using Feature.YiGuo.Framework.Utility.Utils;
using System;
using System.Collections.Generic;
using System.Net.Mime;

namespace SendEmailConsoleApplication1
{
    class Program
    {
        static void Main(string[] args)
        {
            try
            {

                var list = new List<User>();

                for (int i = 0; i < 100; i++)
                {
                    list.Add(new User() { UserId = "UserId" + i, UserName = "UserName" + i });
                }

                var strem = ExcelHelper.Export(list.ToDataTable());

                SMTPEmailSender sender = new SMTPEmailSender("yiguomail.yiguo.com", "ygomp@yiguo.com", "A4FZMH2t");

                sender.From = "ygomp@yiguo.com";
                sender.AddReceiver("chenhegang@yiguo.com");
                sender.Subject = "This is a test";
                sender.Content = "hi,omp team";
                sender.AddAttachment("C://Users//chenhegang//Desktop//发布模板.xlsx", "发布模板.xlsx");
                sender.AddAttachment("C://Users//chenhegang//Desktop//工作周报.xlsx");
                var c = new ContentType("application/vnd.ms-excel")
                {
                    Name = "User.xls"
                };

                sender.AddAttachment(strem, c);
                //sender.AddAttachment(strem, "User", "application/vnd.ms-excel");

                sender.Send();
                System.Console.Out.WriteLine("send ok");
            }
            catch (Exception e)
            {
                System.Console.Out.WriteLine(e.Source + e.Message);
            }

        }
    }

    public class User
    {
        public string UserId { get; set; }
        public string UserName { get; set; }
    }
}
